-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(client): wrap cmd.SetArgs to fix bugs for cmd.SetArgs #18876
Conversation
WalkthroughThe codebase underwent a refactor where the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ? TipsChat with CodeRabbit Bot (
|
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
testutil/cmd.go
Outdated
// SetArgs sets arguments for the command. It is desired to replace the cmd.SetArgs in all test case, as cmd.SetArgs doesn't reset flag value as expected. | ||
// | ||
// see https://github.com/spf13/cobra/issues/2079#issuecomment-1867991505 for more detail info | ||
func SetArgs(cmd *cobra.Command, args []string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be mindful of new public api we add. Can we maybe have this in an internal package?
Concerning using it everywhere in the sdk, we should really really watch out that we don't increase the reliance on the sdk for already extracted modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@julienrbrt Hi sir, I have moved it to internal/testutil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, ty!
…osmos#18876)" This reverts commit ae19acc.
Description
This pr is aim to provide a simple way
testutil.SetArgs
to replacecmd.SetArgs
in test as there is bug forcmd.SetArgs
, see spf13/cobra/issues/2079 for more detail info about the bug.Reason
Refer to pr #18557 added test, it's fussy to explicitly set all args that has changed before in writing unit test. We should concentrate on the new test case, no need to care about what this case's args will take effects to other test cases.
Test
I have replaced
cmd.SetArgs
totestutil.SetArgs
in keys show test, it works well. If this pr LGTY, I will draft a new pr to check if there are test cases that depend on the bug behavior of SetArgs, and replacecmd.SetArgs
totestutil.SetArgs
for all test file.